package com.kool.kreport.task;

import com.kool.kreport.common.util.DateUtil;
import com.kool.kreport.service.DailyReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author luyu
 */
@Component
@Slf4j
public class DailyTask {
    @Resource
    private DailyReportService dailyReportService;

    /**
     * 每天生成日报表
     */
    @Scheduled(cron = "0 0 1 * * ?")
    public void computeDailyReport() {
        log.info("开始生成日报表");
        //生成前1天的日报表，已存在覆盖
        dailyReportService.computeDailyReport(DateUtil.toIntDay(DateUtil.getDateAfter(new Date(), -1)), true);
        log.info("生成日报表成功");
    }
}
